//
//  QDBusCodeManager-Swift.swift
//  QDMetroClient
//
//  Created by YueWen on 2019/3/10.
//  Copyright © 2019 YueWen. All rights reserved.
//

import Foundation

extension QDBusCodeManager {
    
    /// 请求公交二维码
    @objc func requestBusCode(channelType: String,
                                force: Bool = false,
                                complete:@escaping ((String) ->())){
        
        QDNetworkingManager.request(url: QDTransitHostUrl + "/transit/transit_ticket", success: { (msg, data) in
            
            guard let qrcode = data["qrCode"] as? String,
                let retCode = data["retCode"] as? String,
                let success = QRCodeStatusType(rawValue: retCode) else {

                    self.codeDelegate?.codeManager(self, fail: .netFail); return
            }
            
            if success == .success {
                complete(qrcode); return
            }
            
            self.codeDelegate?.codeManager(self, fail:  success.headerErrorType)
            
            
        }) { (msg, errorType) in
            
            self.codeDelegate?.codeManager(self, fail: .netFail)
        }
        
    }
}
